package Operation;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mirac
 * Date: 2025-06-02
 * Time: 21:42
 */
public class DeleteOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("3. 删除图书");
        int sz = bookList.getBookSize();
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要删除的图书的名字：");
        String name = scanner.nextLine();
        int i = 0;
        for (; i < sz; i++) {
            if(bookList.getBook(i).getName().equals(name)) {
                break;
            }
        }

        if(i == sz) {
            System.out.println("书架上没有你要删除的图书。");
            return;
        }

        for (int j = 0; j < sz - 1; j++) {
            bookList.setBooks(j,bookList.getBook(j+1));
        }

        bookList.setBookSize(sz - 1);
        System.out.println("删除完成！");
    }
}
